package com.overoid.diary.ui;

import com.overoid.diary.R;
import com.overoid.diary.ui.common.ActivityImpl;
import com.overoid.diary.ui.common.Constants;
import com.overoid.diary.ui.common.DBHelper;
import com.overoid.diary.ui.day.edit.DayEditActivity;
import com.overoid.diary.ui.picture.PictureActivity;

import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class DayActivity extends ActivityImpl{
	
	private int memo_id = 1;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
			
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.day);
		
		memo_id = getIntent().getIntExtra("memo_id",0);
		
		// data 조회
		DBHelper db = new DBHelper(getApplicationContext());		
		DBHelper.Memo memo = db.getMemo(memo_id);
		
		// text 값 setting
		((TextView)findViewById(R.id.dayTxtTitle)).setText("Memo View \n"+ memo.memoRegistDate);
		
		((TextView)findViewById(R.id.dayTextContents)).setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/JOKERMAN.TTF"));
		((TextView)findViewById(R.id.dayTextContents)).setText(memo.memoContents);
		
		// category 값 setting
		((ImageView)findViewById(R.id.dayImgCategory)).setImageResource(Constants.getCategoryImage((int)memo.memoClassId));
		
		// image button
		Log.d("imageCount ================",""+memo_id);
		Log.d("imageCount ================",""+memo.imageCount);
		if( memo.imageCount == 0){
			
			((ImageButton)findViewById(R.id.dayImgBtnPic)).setVisibility(View.INVISIBLE);
		}
		
		
		
		final ImageButton dayCancle =  (ImageButton)findViewById(R.id.dayBtnCancle);
		dayCancle.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		
		final ImageButton btnEdit =  (ImageButton)findViewById(R.id.dayBtnEdit);
		btnEdit.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				
				Intent in = new Intent(DayActivity.this,DayEditActivity.class);
				in.putExtra("memo_id", memo_id);
				startActivity(in);
				finish();
			}
		});
		
		final ImageButton dayImgBtnPic =  (ImageButton)findViewById(R.id.dayImgBtnPic);
		dayImgBtnPic.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent in = new Intent(DayActivity.this,PictureActivity.class);
				in.putExtra("memo_id", memo_id);
				startActivity(in);
				
			}
		});
		
		final ImageButton dayImgBtnVideo =  (ImageButton)findViewById(R.id.dayImgBtnVideo);
		dayImgBtnVideo.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				
				Intent in = new Intent(DayActivity.this,VideoActivity.class);
				startActivity(in);
			}
		});
		
		
		
	}
}
